function addUser() {
    const username = $("#username").val()
    const mail = $("#email").val()
    const password = $("#password").val()
    const password2 = $("#confirm_password").val()
    const role = $("#role").val()

    $.ajax({
        url: "http://www.woniu-news.com:8082/addUser.php",
        type: "POST",
        xhrFields: {
            withCredentials: true
        },
        data: {
            username,
            mail,
            password,
            password2,
            role
        },
        dataType: "json",
        success: (resp) => {
            if (resp.code === 200) {
                alert(resp.message)
                window.location.href = "user_management.html"

            } else {
                alert(resp.message)
            }
        },
        error: (resp) => {
            alert(resp.message)
        }
    })
}

$(".adduser").click(function () {
    addUser()
})